﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZLWeb.WebApiEntityBase;

namespace ZL.Web.Utility.WeiXinTokenServiceClient
{
    public class WeiXinTokenService: ServiceBase,IWeiXinTokenService
    {

        public Access_token GetComponentAccessToken()
        {
            var url = $"{WeiXinTokenserver}/Api/Component/GetAccess_token";
            var result = httpClient.HttpGet<Access_token>(url, Identity);
            return result;
        }

        public string Getcomponent_access_token()
        {
            Access_token at = GetComponentAccessToken();
            if (at == null) return string.Empty;
            if (at.Errormodel != null) return string.Empty;
            return at.component_access_token;
        }

        public Authorization_info GetWeiXinToken(string appid)
        {
            var url = $"{WeiXinTokenserver}/Api/Component/GetAuthorization_info?Authorization_appid={appid}";
            var info = httpClient.HttpGet<Authorization_info>(url, Identity);
            return info;
        }

        public string GetAccessToken(string appId)
        {
            Authorization_info WeiXinToken = GetWeiXinToken(appId);
            if (WeiXinToken == null) return string.Empty;
            if (WeiXinToken.Errormodel != null) return string.Empty;
            return WeiXinToken.authorizer_access_token;
        }
    }
}
